package com.bobo.netty.service.impl;

import com.bobo.netty.dto.DeviceMsDTO;
import com.bobo.netty.service.ChatService;
import com.bobo.netty.utils.RedisUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.atomic.AtomicInteger;

@Service
public class ChatServiceImpl implements ChatService {
    private Logger LOGGER = LoggerFactory.getLogger(ChatServiceImpl.class);
    @Resource
    private RedisUtils redisUtils;
    public static final String[] names = {"张三", "李四", "王五", "马六"};
    public static AtomicInteger integer = new AtomicInteger();

    @Override
    public Boolean addChannelConnectDevice(DeviceMsDTO deviceMsDTO) {
        if (StringUtils.isBlank(deviceMsDTO.getChannelId())) {
            return false;
        }
        int numOfName = integer.incrementAndGet();
        //张三
//        String userId = "036e24b29d2b4327b89afe3da6e62c35";
        //李四
//        String userId = "ad6ff948c0d24c799f03a36996d20536";
//        String userName = names[RandomUtils.nextInt(0, 3)] + numOfName;
//        redisUtils.hset(ConstantsRedis.USER_PRE + userId, "userName", userName);
//        Map<String, Object> deviceMap = new HashMap<>();
//        deviceMap.put("channelId", deviceMsDTO.getChannelId());
//        deviceMap.put("deviceId", UUID.randomUUID().toString().replace("-", ""));
//        deviceMap.put("connectTime", DateTimeUtils.format(new Date(), DateTimeUtils.DATE_FORMAT));
//        deviceMap.put("userId", userId);
        //绑定用户与通道
//        redisUtils.add(ConstantsRedis.USER_CHANNEL_ID + userId, deviceMsDTO.getChannelId(),60, TimeUnit.MINUTES);
//        LOGGER.info(String.format("channelId:%s,userId:%s", deviceMsDTO.getChannelId(), userId));
        //绑定设备
//        return redisUtils.hmset(ConstantsRedis.DEVICE_PRE + deviceMsDTO.getChannelId(), deviceMap);
        return true;
    }
}
